<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::Locking::Optimistic::ClassMethods</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveRecord::Locking::Optimistic::ClassMethods 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../../files/activerecord/lib/active_record/locking/optimistic_rb.html">activerecord/lib/active_record/locking/optimistic.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-column_defaults">column_defaults</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-locking_column">locking_column</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-locking_column-3D">locking_column=</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-locking_enabled-3F">locking_enabled?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>Q</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-quoted_locking_column">quoted_locking_column</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-reset_locking_column">reset_locking_column</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>U</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-update_counters">update_counters</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    
      <!-- Section constants -->
      <div class="sectiontitle">Constants</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class="attr-name">DEFAULT_LOCKING_COLUMN</td>
            <td>=</td>
            <td class="attr-value">'lock_version'</td>
          </tr>
          
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"></td>
            </tr>
          
        
      </table>
    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-column_defaults">
            
              <b>column_defaults</b>()
            
            <a href="ClassMethods.html#method-i-column_defaults" name="method-i-column_defaults" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-column_defaults_source')" id="l_method-i-column_defaults_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/992d87db02507363a4ad4ab40a3e4c4b32cf0408/activerecord/lib/active_record/locking/optimistic.rb#L167" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-column_defaults_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/locking/optimistic.rb, line 167</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">column_defaults</span>
  <span class="ruby-ivar">@column_defaults</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">defaults</span> = <span class="ruby-keyword">super</span>

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">locking_column</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">lock_optimistically</span>
      <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">locking_column</span>] <span class="ruby-operator">||=</span> <span class="ruby-number">0</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">defaults</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-locking_column">
            
              <b>locking_column</b>()
            
            <a href="ClassMethods.html#method-i-locking_column" name="method-i-locking_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>The version column used for optimistic locking. Defaults to
<code>lock_version</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-locking_column_source')" id="l_method-i-locking_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/992d87db02507363a4ad4ab40a3e4c4b32cf0408/activerecord/lib/active_record/locking/optimistic.rb#L145" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-locking_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/locking/optimistic.rb, line 145</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">locking_column</span>
  <span class="ruby-identifier">reset_locking_column</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@locking_column</span>)
  <span class="ruby-ivar">@locking_column</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-locking_column-3D">
            
              <b>locking_column=</b>(value)
            
            <a href="ClassMethods.html#method-i-locking_column-3D" name="method-i-locking_column-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Set the column to use for optimistic locking. Defaults to
<code>lock_version</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-locking_column-3D_source')" id="l_method-i-locking_column-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/992d87db02507363a4ad4ab40a3e4c4b32cf0408/activerecord/lib/active_record/locking/optimistic.rb#L140" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-locking_column-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/locking/optimistic.rb, line 140</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">locking_column=</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-ivar">@locking_column</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-locking_enabled-3F">
            
              <b>locking_enabled?</b>()
            
            <a href="ClassMethods.html#method-i-locking_enabled-3F" name="method-i-locking_enabled-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns true if the <code>lock_optimistically</code> flag is set to true
(which it is, by default) and the table includes the
<code>locking_column</code> column (defaults to <code>lock_version</code>).</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-locking_enabled-3F_source')" id="l_method-i-locking_enabled-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/992d87db02507363a4ad4ab40a3e4c4b32cf0408/activerecord/lib/active_record/locking/optimistic.rb#L135" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-locking_enabled-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/locking/optimistic.rb, line 135</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">locking_enabled?</span>
  <span class="ruby-identifier">lock_optimistically</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">locking_column</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-quoted_locking_column">
            
              <b>quoted_locking_column</b>()
            
            <a href="ClassMethods.html#method-i-quoted_locking_column" name="method-i-quoted_locking_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Quote the column name used for optimistic locking.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-quoted_locking_column_source')" id="l_method-i-quoted_locking_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/992d87db02507363a4ad4ab40a3e4c4b32cf0408/activerecord/lib/active_record/locking/optimistic.rb#L151" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-quoted_locking_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/locking/optimistic.rb, line 151</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">quoted_locking_column</span>
  <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_column_name</span>(<span class="ruby-identifier">locking_column</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-reset_locking_column">
            
              <b>reset_locking_column</b>()
            
            <a href="ClassMethods.html#method-i-reset_locking_column" name="method-i-reset_locking_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Reset the column used for optimistic locking back to the
<code>lock_version</code> default.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-reset_locking_column_source')" id="l_method-i-reset_locking_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/992d87db02507363a4ad4ab40a3e4c4b32cf0408/activerecord/lib/active_record/locking/optimistic.rb#L156" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-reset_locking_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/locking/optimistic.rb, line 156</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">reset_locking_column</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">locking_column</span> = <span class="ruby-constant">DEFAULT_LOCKING_COLUMN</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-update_counters">
            
              <b>update_counters</b>(id, counters)
            
            <a href="ClassMethods.html#method-i-update_counters" name="method-i-update_counters" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Make sure the lock version column gets updated when counters are updated.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-update_counters_source')" id="l_method-i-update_counters_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/992d87db02507363a4ad4ab40a3e4c4b32cf0408/activerecord/lib/active_record/locking/optimistic.rb#L162" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-update_counters_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/locking/optimistic.rb, line 162</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">update_counters</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counters</span>)
  <span class="ruby-identifier">counters</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">locking_column</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">1</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">locking_enabled?</span>
  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    